XfCreateBoxNet = {
	private ["_box","_box_pos","_vehicle","_box_side","_box_type","_param"];
	diag_log Format["(%1)[%2]: %3 %4",diag_tickTime,"netinitclient.sqf", "XfCreateBoxNet", _this];
	_box_side = d_own_side;
	_box_type = d_default_ammo_box;
	_vehicle = objNull;
	_box_pos = _this select 0;
	_marker_name = "";
	if (count _this > 1) then {_vehicle = _this select 1;};
	if (count _this > 2) then {
		_param = _this select 2;
		if (!IsNil "_param") then {if(_param != "") then {_marker_name = _param;};};
	};
	if (count _this > 3) then {
		_param = _this select 3;
		if (!IsNil "_param") then {if(_param != "") then {_box_side = _param;};};
	};
	if (count _this > 4) then {
		_param = _this select 4;
		if (!IsNil "_param") then {if(_param != "") then {_box_type = _param;};};
	};
	_box = _box_type createVehicleLocal _box_pos;
	if (_marker_name == "") then {_marker_name=Format["box%1%2%3",floor(_box_pos select 0),floor(_box_pos select 1),floor(_box_pos select 2)];};
	_box setVariable ["map_marker", _marker_name];
	_box setVariable ["ARTY_N_LOG_IGNORE_OBJECT",true];
	[_marker_name, _box_pos, "ICON", "ColorBlack", [0.6,0.6],"",0,"marker","",0.5] call XfCreateMarkerLocal;
	_box setPos _box_pos;
	player reveal _box;
	_box addEventHandler ["killed",{["d_r_box", [position (_this select 0),ObjNull,((_this select 0) getVariable "map_marker")]] call XNetCallEvent;deleteVehicle (_this select 0);}];
	[_box,_box_side] spawn {
		private ["_box_object","_box_side"];
		_box_object = _this select 0;
		_box_side = _this select 1;
		if (!isnil("_box_object")) then {
			while {alive _box_object} do {
				diag_log Format["(%1)[%2]: %3 %4",diag_tickTime,"netinitclient.sqf","Filling a box at ", ((getPos _box_object) call XfGPSCoords)];
				[_box_object,_box_side] spawn x_weaponcargo;
				// We wait that the player gets close to the box before starting the refill wait. This avoids unnecessary refill when the player is in the field.
				waituntil { (!alive _box_object) OR ((player distance _box_object) < 100) };
				// We wait that the player is far enough from the box before refilling it.
				waituntil { (!alive _box_object) OR ((player distance _box_object) > 50) };
				If (alive _box_object) then { sleep 1200; };
			};	
		};
	};
	_box;
};

XfRemoveBoxNet = {
	private ["_nobjs","_box","_box_marker"];
	diag_log Format["(%1)[%2]: %3 %4",diag_tickTime,"netinitclient.sqf", "XfRemoveBoxNet", _this];
	if (typename _this != "ARRAY") exitWith {diag_log Format["(%1)[%2]: %3 %4",diag_tickTime,"netinitclient.sqf", "XfRemoveBoxNet", "Invalid Parameter"];};
	_nobjs = nearestObjects [(_this select 0), d_all_ammoboxes, 10];
	if (count _this > 2) then {_box_marker = (_this select 2);};
	if (count _nobjs > 0) then {
		_box = _nobjs select 0;
		_box_marker = _box getVariable "map_marker";
		deleteVehicle _box;
	};
	if (!isNil "_box_marker") then {
		if (_box_marker != "") then { deleteMarkerLocal _box_marker; };
	};
};

XfCreateAirBoxNet = {
	private ["_array","_pos","_box"];
	_array = _this;
	diag_log Format["(%1)[%2]: %3 %4",diag_tickTime,"netinitclient.sqf", "XfCreateAirBoxNet", _this];
	// you can call the function with both an array with the position + type or the position only
	If ((typename _array) == "ARRAY" ) then {
		_pos = _this select 0;
	} else {
		_pos = _array;
		_array = [_pos];
	};
	_pos = [_pos select 0, _pos select 1, 0];
	_array set [0,_pos];
	_box = _array call XfCreateBoxNet;
	diag_log Format["(%1)[%2]: %3 %4",diag_tickTime,"netinitclient.sqf", "Box placed at", (getPos _box) call XfGPSCoords];
};

XfAirTaxiNet = {
	if (player == (_this select 1)) then {
		switch (_this select 0) do {
			case 0: {localize "MSG_DOM_AIRTAXIONWAY" call XfHQChat};
			case 1: {localize "MSG_DOM_AIRTAXIYOUDIED" call XfHQChat;d_heli_taxi_available = true};
			case 2: {localize "MSG_DOM_AIRTAXIDAMAGED" call XfHQChat;d_heli_taxi_available = true};
			case 3: {localize "MSG_DOM_AIRTAXIHEADING" call XfHQChat};
			case 4: {localize "MSG_DOM_AIRTAXILEAVING" call XfHQChat;d_heli_taxi_available = true};
			case 5: {localize "MSG_DOM_AIRTAXISTARTS" call XfHQChat};
			case 6: {localize "MSG_DOM_AIRTAXIARRIVING" call XfHQChat};
			case 7: {localize "MSG_DOM_AIRTAXINOTAVAILABLE" call XfHQChat};
			case 8: {localize "MSG_DOM_AIRTAXISTEPINLAST" call XfHQChat};
			case 9: {localize "MSG_DOM_AIRTAXITOBASE" call XfHQChat};
			case 10: {localize "MSG_DOM_AIRTAXINOTVALIDSPOT" call XfHQChat};
			case 11: {localize "MSG_DOM_AIRTAXINOBODYIN" call XfHQChat};
		};
	};
};

XfDropAnswer = {
	if (player == (_this select 1)) then {
		switch (_this select 0) do {
			case 0: {localize "MSG_DOM_DROPSTARTING" call XfHQChat};
			case 1: {localize "MSG_DOM_DROPONWAY" call XfHQChat};
			case 2: {localize "MSG_DOM_DROPARRIVING" call XfHQChat};
			case 3: {localize "MSG_DOM_DROPDAMAGED" call XfHQChat};
			case 4: {localize "MSG_DOM_DROPDONE" call XfHQChat};
			case 5: {localize "MSG_DOM_DROPCARRIERLOST" call XfHQChat};
			case 6: {localize "MSG_DOM_DROPTOBASE" call XfHQChat};
		};
	};
};

XfMHQdeplNet = {
	private ["_mhq", "_isdeployed", "_name", "_vside"];
	_mhq = _this select 0;
	_isdeployed = _this select 1;
	_name = _mhq getVariable "d_vec_name";
	if (isNil "_name") exitWith {};
	_m = _mhq getVariable "d_marker";
	if (_isdeployed) then {
		_mhq lock true;
		(format [localize "MSG_DOM_MHQDEPLOYED", _name]) call XfHQChat;
		if (!isNil "_m") then {_m setMarkerTextLocal ((_mhq getVariable "d_marker_text") + localize "MSG_DOM_MHQMRKDEPLOYED")};
	} else {
		_mhq lock false;
		(format [localize "MSG_DOM_MHQUNDEPLOYED", _name]) call XfHQChat;
		if (!isNil "_m") then {_m setMarkerTextLocal (_mhq getVariable "d_marker_text")};
	};
};
